<?php
// 本类由系统自动生成，仅供测试用途
class PublicAction extends Action {
    public function login(){

    	if (IS_POST) {
    		$username = $this->_post('name');
    		$password =  $this->_post('pwd');

    		$this->validUser($username,$password);
    	}else{
    		$this->display(); 
    	}
    	
    }

    public function loginout(){
		session('user',null); // 删除name
        session('userid',null); // 删除name
        // $this->redirect('Admin/Public/login');
        redirect(U('Admin/Public/login'));
    }

    public function verify(){
		echo "verify";
    }

    private function validUser($username,$password)
    {
        $adminInfo = D('Admin')->validateUser($username,$password);
    	if($adminInfo) {
    		session('user',$adminInfo['username']);
            session('userid',$adminInfo['id']);
            session('userinfo',$adminInfo);
    		// $this->redirect('Admin/Index/index');
            redirect(U('Admin/Index/index'));
    	}else{
    		C('LAYOUT_ON',false);
    		$this->error('用户名密码错误！');
    	}
    }
}